<%@ page import="java.util.Date" %>
<%@ page import="java.text.SimpleDateFormat" %>
<%@ page import="java.util.Calendar" %><%--
  Created by IntelliJ IDEA.
  User: bb
  Date: 2021/10/19
  Time: 21:52
  To change this template use File | Settings | File Templates.
--%>
<%@ page contentType="text/html;charset=UTF-8" language="java" %>
<html>
<head>
    <title>Title</title>
    <link href="jquery-easyui-1.7.0/themes/default/easyui.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/themes/icon.css" rel="stylesheet" type="text/css" />
    <link href="jquery-easyui-1.7.0/demo/demo.css" rel="stylesheet" type="text/css" />
    <script src="jquery-easyui-1.7.0/jquery.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/jquery.easyui.min.js" type="text/javascript"></script>
    <script src="jquery-easyui-1.7.0/locale/easyui-lang-zh_CN.js" type="text/javascript"></script>
</head>
<body>
    <%--searchBar_Order--%>
    <div id="searchBar_Order" style="padding: 2px 5px">
        <form id="searchForm" style="padding: 3px">
            订单编号：&nbsp;<input class="easyui-textbox" id="orderId" name="orderId" style="width: 110px;" />&nbsp;&nbsp;&nbsp;
            <%--统计订单：&nbsp;<select class="easyui-combobox" id="fixRange" name="statisticalOrder" style="width: 110px">
                            <option value="请选择..." selected>请选择...</option>
                            <option value="一年内">一年内</option>
                            <option value="一个月内">一个月内</option>
                            <option value="一周内">一周内</option>
                        </select>&nbsp;&nbsp;&nbsp;--%>
            <br>
            客户名称：&nbsp;<input class="easyui-combobox" id="customerName" name="customerName" style="width: 110px"
                              data-options="valueField:'id', textField:'userName', url:'userInfo/getValidUser'"/>&nbsp;&nbsp;&nbsp;
            订单状态：&nbsp;<select class="easyui-combobox" id="orderStatus" name="orderStatus" style="width: 110px">
                            <option value="请选择..." selected>请选择...</option>
                            <option value="未付款">未付款</option>
                            <option value="已付款">已付款</option>
                            <option value="未发货">未发货</option>
                            <option value="已发货">已发货</option>
                            <option value="已完成">已完成</option>
                          </select>&nbsp;&nbsp;&nbsp;
            订单时间：&nbsp;<input class="easyui-datebox" id="orderDate1" name="orderDate1" style="width: 110px"/>
            ~ <input class="easyui-datebox" id="orderDate2" name="orderDate2" style="width: 110px"/>
            <a href="javascript:void(0)" class="easyui-linkbutton" iconCls="icon-search" plain="true" onclick="searchOrder();">查找</a>
        </form>
    </div>
    <%--datagrid--%>
    <div id="datagrid_searchOrder" class="easyui-datagrid"></div>
    <%--toolbar--%>
    <div id="toolbar_searchOrder" style="padding: 2px 5px">
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-edit" plain="true" onclick="edit();">查看明细</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-remove" plain="true" onclick="remove();">删除订单</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-tip" plain="true" onclick="statisticalWeek();">统计本周订单</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-tip" plain="true" onclick="statisticalMonth();">统计当月订单</a>
        <a href="javascript:void(0)" class="easyui-linkbutton" iconcls="icon-tip" plain="true" onclick="statisticalYear();">统计今年订单</a>
    </div>

    <script>
        $(function (){
            $('#datagrid_searchOrder').datagrid({
                singleSelect:false,
                fit:true,
                fitColumn:true,
                rownumbers:true,
                pagination:true,
                pageSize:10,
                pageList:[5,10,15,20],
                header:'#searchBar_Order',
                toolbar:'#toolbar_searchOrder',
                url:'order/searchOrder',
                //queryParams:{},//用于设置传递到后台的参数列表
                columns:[[{
                    title:'序号',
                    field:'id',
                    align:'center',
                    checkbox:true
                },{
                    title:'订单客户',
                    field: 'user',
                    width: 120,
                    formatter:function (value,row,index){
                        if (row.user){
                            return row.user.userName;
                        }
                        return value;
                    }
                },{
                    field: 'status',
                    title: '订单状态',
                    width: 90
                },{
                    field: 'ordertime',
                    title: '订单时间',
                    width:260
                },{
                    field: 'orderprice',
                    title: '订单金额',
                    width: 90
                }]]
            })
        })
    </script><%--datagrid--%>
    <script>
        function searchOrder(){
            var orderId = $('#orderId').val();//var orderId = $('#orderId').textbox('getValue');
            var customerName = $('#customerName').combobox('getValue');
            var orderStatus = $('#orderStatus').combobox('getValue');
            var orderDate1 = $('#orderDate1').datebox('getValue');
            var orderDate2 = $('#orderDate2').datebox('getValue');
            if(!orderId){
                orderId = 0
            }
            if (!customerName){
                customerName = 0
            }
            if (!orderDate1){
                orderDate1 = '1999-1-1'
            }
            if (!orderDate2){
                orderDate2 = '2999-1-1'
            }
            $('#datagrid_searchOrder').datagrid('load',{
                'id':orderId,
                'uid':customerName,
                'status':orderStatus,
                'orderTimeFrom':orderDate1,
                'orderTimeTo':orderDate2  //传向后台的参数 跟 POJO对象属性要一致
            });
        }
    </script><%--searchBar_Order--%>
    <script>
        function edit(){
            var rows = $('#datagrid_searchOrder').datagrid('getSelections');
            var len = rows.length;
            //console.log(rows)//调试
            if (len == 1) {
                if ( $('#tabs').tabs('exists','订单明细') ) {
                    $('#tabs').tabs('close','订单明细')
                }
                $('#tabs').tabs('add', {
                    title:'订单明细',
                    href:'order/getOrderInfo?oid=' + rows[0].id,
                    closable:true
                });
            }else if(len < 0){
                $.messager.alert('提示','请选择需要查看的订单','info');
            }else {
                $.messager.alert('提示','只可以选择一个噢！','info');
            }
        }
        function remove(){
            var rows = $('#datagrid_searchOrder').datagrid('getSelections');
            var len = rows.length
            if (len > 0){
                $.messager.confirm('Confirm','确认要删除吗？',function (r){
                    //console.log(r)//调试
                    if (r){
                        var ids = "";
                        //获取选中行的id
                        for (var i = 0; i < len; i++){
                            ids += rows[i].id;
                            if (i+1 != len){
                                ids += ',';
                            }
                        }
                        $.post('order/deleteOrder', {
                            oids : ids
                        }, function (result){
                            if (result.success == 'true'){
                                $('#datagrid_searchOrder').datagrid('reload');
                                $.messager.show({
                                    title:'提示信息',
                                    msg:result.count + result.message
                                });
                            }else {
                                $.messager.show({
                                    title:'提示信息',
                                    msg:result.message
                                });
                            }
                        },'json');
                    }
                });
            }else{
                $.messager.alert('提示','请选择要删除的行！','info');
            }
        }
                    <%
                        SimpleDateFormat simpleDateFormat = new SimpleDateFormat("yyyy-MM-dd");
                        Calendar calendar = Calendar.getInstance();
                        calendar.setTime(new Date());


                        Date date = calendar.getTime();
                        String thisYear = simpleDateFormat.format(date);
                        thisYear = thisYear.substring(0,4) + "-01-01";


                        date = calendar.getTime();
                        String thisMonth = simpleDateFormat.format(date).substring(0,7) + "-01";

                        calendar.add(Calendar.DAY_OF_WEEK,-1);
                        date = calendar.getTime();
                        String lastWeek = simpleDateFormat.format(date);

                        String today = simpleDateFormat.format(new Date());
                    %>
        function statisticalMonth(){
            $('#datagrid_searchOrder').datagrid('load',{
                'orderTimeFrom':"<%=thisMonth%>",
                'orderTimeTo':"<%=today%>"  //传向后台的参数 跟 POJO对象属性要一致
            });
        }

        function statisticalYear(){
            $('#datagrid_searchOrder').datagrid('load',{
                'orderTimeFrom':"<%=thisYear%>",
                'orderTimeTo':"<%=today%>"  //传向后台的参数 跟 POJO对象属性要一致
            });
        }

        function statisticalWeek(){
            $('#datagrid_searchOrder').datagrid('load',{
                'orderTimeFrom':"<%=lastWeek%>",
                'orderTimeTo':"<%=today%>"  //传向后台的参数 跟 POJO对象属性要一致
            });
        }
    </script><%--toolbar--%>
</body>
</html>
